How to create statistics on national and regional electricity consumption and electricity production
The script below can be used as a starting point for creating statistics on electricity consumption and electricity production that appear from electricity readings from electricity meters throughout the country. It first generates monthly national figures for consumption and production, as well as average figures over the whole year (2023). In part 2, detailed regional statistics are created on electricity production, electricity consumption and net production in June 2023 for households that produce electricity, e.g. through solar cells or wind turbines.
Note that the results generated by the script cannot be considered official statistics without further quality control and processing of the data.
require no.ssb.fdb:34 as db
create-dataset elhubdata
for mth, day in 1:12, 31 28 31 30 31 30 31 31 30 31 30 31
import db/ELHUB_PERS_STROMFORBRUK date_fmt(2023, $mth, $day) as electricityconsumption++$mth, outer_join
import db/ELHUB_PERS_KRAFTPRODUKSJON date_fmt(2023, $mth, $day) as powerproduction++$mth, outer_join
end
textblock
Year for the entire population
-----------------------------
endblock
textblock
Average electricity consumption month by month
endblock
barchart(mean) electricityconsumption1 electricityconsumption2 electricityconsumption3 electricityconsumption4 electricityconsumption5 electricityconsumption6 electricityconsumption7 electricityconsumption8 electricityconsumption9 electricityconsumption10 electricityconsumption11 electricityconsumption12
textblock
Average power production month by month
endblock
barchart(mean) powerproduction1 powerproduction2 powerproduction3 powerproduction4 powerproduction5 powerproduction6 powerproduction7 powerproduction8 powerproduction9 powerproduction10 powerproduction11 powerproduction12
generate avgconsumption = rowmean(electricityconsumption1, electricityconsumption2, electricityconsumption3, electricityconsumption4, electricityconsumption5, electricityconsumption6, electricityconsumption7, electricityconsumption8, electricityconsumption9, electricityconsumption10, electricityconsumption11, electricityconsumption12)
generate totalconsumption = rowtotal(electricityconsumption1, electricityconsumption2, electricityconsumption3, electricityconsumption4, electricityconsumption5, electricityconsumption6, electricityconsumption7, electricityconsumption8, electricityconsumption9, electricityconsumption10, electricityconsumption11, electricityconsumption12)
generate avgproduction = rowmean(powerproduction1, powerproduction2, powerproduction3, powerproduction4, powerproduction5, powerproduction6, powerproduction7, powerproduction8, powerproduction9, powerproduction10, powerproduction11, powerproduction12)
generate totalproduction = rowtotal(powerproduction1, powerproduction2, powerproduction3, powerproduction4, powerproduction5, powerproduction6, powerproduction7, powerproduction8, powerproduction9, powerproduction10, powerproduction11, powerproduction12)
summarize avgconsumption totalconsumption avgproduction totalproduction
textblock
Statistics for power producers in the peak season month June
-------------------------------------------------------
endblock
clone-dataset elhubdata powerproducers
use powerproducers
keep powerproduction6 electricityconsumption6
generate powerproducer6 = !sysmiss(powerproduction6)
generate netproduction6 = powerproduction6 - electricityconsumption6
summarize powerproduction6 electricityconsumption6 netproduction6 if powerproducer6
import db/ELHUB_PERS_PRISOMRADE 2023-06-30 as pricearea6
import db/ELHUB_PERS_MALEPUNKT_ADR_KOMMUNE 2023-06-30 as municipality6
import db/ELHUB_PERS_MALEPUNKTID_FNR 2023-06-30 as personid6
textblock
Average power production, electricity consumption and net production for power producers in June 2023
endblock
barchart(mean) powerproduction6 electricityconsumption6 netproduction6 if powerproducer6
textblock
Average power production, electricity consumption and net production for power producers in June 2023, divided by price area
endblock
barchart(mean) powerproduction6 electricityconsumption6 netproduction6 if powerproducer6, over(pricearea6)
textblock
Average power production for power producers in June 2023, divided by municipality
endblock
tabulate municipality6 if powerproducer6, summarize(powerproduction6) rowsort bottom(10)
textblock
Average net production for power producers in June 2023, divided by municipality
endblock
tabulate municipality6 if powerproducer6, summarize(netproduction6) rowsort bottom(10)
textblock
Statistics at person level (people can own multiple homes/meter points)
endblock
collapse(sum) powerproduction6 electricityconsumption6, by(personid6)
generate netproduction6 = powerproduction6 - electricityconsumption6
generate powerproducer = powerproduction6 > 0
define-labels producerlbl 0 "Not a power producer" 1 "Power producer"
assign-labels powerproducer producerlbl
summarize if powerproducer
textblock
Average power production, electricity consumption and net production for power producers in June 2023 per person
endblock
barchart(mean) powerproduction6 electricityconsumption6 netproduction6 if powerproducer